package com.ruoyi.article.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.SysNotice;
import com.ruoyi.system.service.ISysNoticeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.article.domain.ZBug;
import com.ruoyi.article.service.IZBugService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * bug描述Controller
 * 
 * @author ruoyi
 * @date 2025-01-13
 */
@RestController
@RequestMapping("/article/bug")
public class ZBugController extends BaseController
{
    @Autowired
    private IZBugService zBugService;

    @Autowired
    private ISysNoticeService noticeService;
    /**
     * 查询bug描述列表
     */
    @PreAuthorize("@ss.hasPermi('article:bug:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZBug zBug)
    {
        startPage();
        List<ZBug> list = zBugService.list();
        return getDataTable(list);
    }

    /**
     * 导出bug描述列表
     */
    @PreAuthorize("@ss.hasPermi('article:bug:export')")
    @Log(title = "bug描述", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZBug zBug)
    {
        List<ZBug> list = zBugService.selectZBugList(zBug);
        ExcelUtil<ZBug> util = new ExcelUtil<ZBug>(ZBug.class);
        util.exportExcel(response, list, "bug描述数据");
    }

    /**
     * 获取bug描述详细信息
     */
    @PreAuthorize("@ss.hasPermi('article:bug:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zBugService.selectZBugById(id));
    }

    /**
     * 新增bug描述
     */
    @PreAuthorize("@ss.hasPermi('article:bug:add')")
    @Log(title = "bug描述", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZBug zBug)
    {
        return toAjax(zBugService.save(zBug));
    }

    /**
     * 修改bug描述
     */
    @PreAuthorize("@ss.hasPermi('article:bug:edit')")
    @Log(title = "bug描述", businessType = BusinessType.UPDATE)
    @Transactional
    @PutMapping
    public AjaxResult edit(@RequestBody ZBug zBug)
    {
        zBug.setStatus(true);
        //新增私人通知
        SysNotice sysNotice = new SysNotice();
        sysNotice.setNoticeTitle("bug反馈");
        sysNotice.setNoticeType("3");
        sysNotice.setNoticeContent("您提交的bug反馈已处理");
        sysNotice.setStatus("0");
        sysNotice.setUserId(zBug.getUserId());
        noticeService.insertNotice(sysNotice);

        return toAjax(zBugService.updateById(zBug));
    }

    /**
     * 删除bug描述
     */
    @PreAuthorize("@ss.hasPermi('article:bug:remove')")
    @Log(title = "bug描述", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zBugService.deleteZBugByIds(ids));
    }
}
